<template>
    <a-form ref="formRef" :model="formData">
        <a-form-item field="position" label="类型" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-radio-group v-model="formData.position">
                <a-radio :value="index" v-for="(item,index) in props.position">{{ item }}</a-radio>
            </a-radio-group>
        </a-form-item>
        <a-form-item field="sort" label="排序" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input-number v-model="formData.sort" placeholder="请输入排序" />
        </a-form-item>
        <a-form-item field="img" label="图片" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <ma-upload v-model="formData.img" title="图片" type="image"></ma-upload>
        </a-form-item>
    </a-form>
</template>
<script  setup>
import { ref } from "vue";
import request from '@/api/rotation'
import { Message } from "@arco-design/web-vue";
const emit = defineEmits(["refreshList"]);

const props = defineProps({
    id: [String, Number],
    position: {
        type: Array,
        default: () => []
    }
});

const formData = ref({});

let default_value = ref([]);
const getDeta = async () => {
    let { data: { data } } = await request.get_deta(props.id);
    let date = [data.start_date, data.end_date];
    default_value.value = date;
    formData.value = data;
};
props.id ? getDeta() : "";

const submit = async () => {
    await request.save(formData.value);
    Message.success("保存成功");
    setTimeout(() => emit("refreshList"), 500);
};
defineExpose({ submit });
</script>